/**
 * 创建redis连接服务对象并暴露
 */

 const configs = require('../config')

const redis = require("redis")

async  function setup_redis() {
	let redis_client = redis.createClient(configs.redis_config.PORT, configs.redis_config.HOST)
	await redis_client.auth(configs.redis_config.PASSWORD)
	await redis_client.on('error', error => {
	    console.log('redis server is error!\n' + error)
	})
	
	await redis_client.on('connect', () => {
		console.log('redis server is connected!')
	})

	await redis_client.on('end', () => {
		console.log('redis server is end')
	})
	return redis_client
}

module.exports.setup_redis = setup_redis()
